package com.atguigu4.connection;

import com.alibaba.druid.pool.DruidDataSourceFactory;
import org.junit.Test;

import javax.sql.DataSource;
import java.io.InputStream;
import java.sql.Connection;
import java.util.Properties;

/**
 * 德鲁伊 数据库连接池
 * @auther user
 * @date 2021/12/10 - 4:16
 */
public class DruidTest {
    @Test
    public void testGetConnection() throws Exception{
        //加载配置文件
        Properties properties = new Properties();
        InputStream inputStream = ClassLoader.getSystemClassLoader().getResourceAsStream("druid.properties");
        properties.load(inputStream);
        //创建数据库连接池
        DataSource ds = DruidDataSourceFactory.createDataSource(properties);
        Connection connection = ds.getConnection();
        System.out.println("connection = " + connection);
    }

}
